package cn.com.hhrcw.resumeDeliveryConfig.service.impl;

import cn.com.hhrcw.entity.CvResume;
import cn.com.hhrcw.resumeDeliveryConfig.entity.ResumeDeliveryConfig;
import cn.com.hhrcw.resumeDeliveryConfig.mapper.ResumeDeliveryConfigMapper;
import cn.com.hhrcw.resumeDeliveryConfig.service.IResumeDeliveryConfigService;
import cn.com.hhrcw.resumeDeliveryConfig.vo.ConfigVO;
import cn.com.hhrcw.resumeDeliveryConfig.vo.ResumeInfoVO;
import cn.com.hhrcw.service.EnterpriseService2;
import cn.com.hhrcw.service.ICvResumeService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
    *  服务实现类
    * </p>
 *
 * @author shengli
 * @since 2021-12-27
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ResumeDeliveryConfigServiceImpl extends ServiceImpl<ResumeDeliveryConfigMapper, ResumeDeliveryConfig> implements IResumeDeliveryConfigService {


    @Autowired
    private ICvResumeService cvResumeService;

    @Autowired
    private EnterpriseService2 enterpriseService2;

    @Override
    public Boolean verifyPosition(String objId, String userId, String resumeId) {
        Assert.isFalse(StrUtil.isBlank(resumeId), "请选择投递的简历！");
        ResumeDeliveryConfig resumeDeliveryConfig = this.lambdaQuery().eq(ResumeDeliveryConfig::getObjId, objId).one();
        if (null != resumeDeliveryConfig) {
            if (StrUtil.isNotBlank(resumeId)) {
                CvResume byId = cvResumeService.getById(resumeId);
                //不支持投递附件简历
                Assert.isFalse(!resumeDeliveryConfig.getAttachmentResumeFlag() && byId.getType() == 1, StrUtil.format("该{}不支持投递附件简历！", StrUtil.equals(resumeDeliveryConfig.getConfigType(), "special_session") ? "专场" : "职位"));
                if (resumeDeliveryConfig.getAttachmentResumeFlag().booleanValue() && byId.getType() == 1) {
                    //支持投递附件简历且投递的简历为附件
                    return true;
                }

            }
            ConfigVO configVO = JSONUtil.toBean(JSONUtil.parseObj(resumeDeliveryConfig.getConfigJson()), ConfigVO.class);
            //根据简历获取简历详细信息
            ResumeInfoVO resumeInfo = enterpriseService2.getResumeInfo2(resumeId);
            //期望职位
            if (configVO.getWorkIntentions().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getWorkIntentions()), "请补充期望职位后投递！");
            }
            //工作实习经历
            if (configVO.getUserWorkInfos().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getUserWorkInfos()), "请补充工作/实习经历后投递！");
            }
            //教育经历
            if (configVO.getUserEduInfos().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getUserEduInfos()), "请补充教育经历后投递！");
            }
            //项目经历
            if (configVO.getProjectInfos().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getProjectInfos()), "请补充项目经历后投递！");
            }
            //培训经历
            if (configVO.getTrainInfos().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getTrainInfos()), "请补充培训经历后投递！");
            }
            //语言能力
            if (configVO.getLanguageLevelInfos().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getLanguageLevelInfos()), "请补充语言能力后投递！");
            }
            //职业特长与技能
            if (configVO.getSkillsInfos().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getSkillsInfos()), "请补充职业特长与技能后投递！");
            }
            //证书
            if (configVO.getCertificateInfos().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getCertificateInfos()), "请补充证书后投递！");
            }
            //家庭成员及重要社会关系
            if (configVO.getFamilyMembers().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getFamilyMembers()), "请补充家庭成员及重要社会关系后投递！");
            }
            //附件
            if (configVO.getFiles().booleanValue()) {
                Assert.isFalse(CollUtil.isEmpty(resumeInfo.getFiles()), "请补充简历中附件后投递！");
            }
            return true;
        }
        return true;
    }
}
